package com.runen.infinitemovement.adapter;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.activity.IntroduceMyLoadActivity;
import com.runen.infinitemovement.activity.IntroduceWeLoadActivity;
import com.runen.infinitemovement.model.entity.IntroduceEntity;
import com.runen.infinitemovement.model.enums.SPCompat;
import com.runen.infinitemovement.tool.AppUtils;
import com.runen.rxnetlibrary.utils.SharePreferenceUtils;

/**
 * Create by LiaoDuanHong
 * Create on
 */
public class IntroduceAdapter extends BaseMultiItemQuickAdapter<IntroduceEntity, BaseViewHolder> {
    private Activity context;

    public IntroduceAdapter(Activity context) {
        super();
        this.context = context;
        addItemType(IntroduceEntity.ONE, R.layout.item_introduce_1);
        addItemType(IntroduceEntity.TWO, R.layout.item_introduce_2);
        addItemType(IntroduceEntity.THREE, R.layout.item_introduce_my_road_1);
        addItemType(IntroduceEntity.FOUR, R.layout.item_introduce_my_road_2);
        addItemType(IntroduceEntity.FIVE, R.layout.item_introduce_we_road_1);
        addItemType(IntroduceEntity.SIX, R.layout.item_introduce_we_road_2);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, IntroduceEntity dataEntity) {
        ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(baseViewHolder.itemView, "alpha", 0f, 1f);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(5000);
        animatorSet.play(alphaAnim);
        animatorSet.start();
        switch (baseViewHolder.getItemViewType()) {
            case IntroduceEntity.ONE:
                VideoView videoView = baseViewHolder.findView(R.id.vv_video);
                //加载指定的视频文件
                String path = "https://static01.futnow.cn/Act-ss-mp4-sd/bb795157690f41c2b91d6c2270b6ba03/%E4%B8%AD%E5%9B%BD%E5%85%B1%E4%BA%A7%E5%85%9A%E7%99%BE%E5%B9%B4%E8%BF%B0%E8%81%8C%E6%8A%A5%E5%91%8A.mp4";
                videoView.setVideoPath(path);

                //创建MediaController对象
                MediaController mediaController = new MediaController(context);

                //VideoView与MediaController建立关联
                videoView.setMediaController(mediaController);
                //让VideoView获取焦点
                videoView.requestFocus();

                animatorSet.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        videoView.start();
                    }
                });
                break;
            case IntroduceEntity.TWO:
                ImageView imageView = baseViewHolder.findView(R.id.iv_my_start);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SharePreferenceUtils.putBoolean(context, SPCompat.FIRST_START_APP, false);
                        AppUtils.jumpToMain(context);
                    }
                });
            case IntroduceEntity.THREE:
                break;
            case IntroduceEntity.FOUR:
                TextView tv_start = baseViewHolder.findView(R.id.tv_start);
                tv_start.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SharePreferenceUtils.putBoolean(context, SPCompat.FIRST_START_MY_LONG_ROAD, false);
                        context.finish();
                    }
                });
                break;
            case IntroduceEntity.FIVE:
                break;
            case IntroduceEntity.SIX:
                TextView tv_understand = baseViewHolder.findView(R.id.tv_understand);
                tv_understand.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SharePreferenceUtils.putBoolean(context, SPCompat.FIRST_START_WE_LONG_ROAD, false);
                        context.finish();
                    }
                });
        }
    }
}
